package com.example.administrator.q1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

public class list_view_Activity extends AppCompatActivity implements AdapterView.OnItemClickListener, MyPersonAdapter.InnerItemOnclickListener{

    ListView listView;
    List<Person> myList = new ArrayList<Person>();
    // int [] arr = new int[]{1, 2, 3, 4};
    Person[] personList = new Person[15];

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_view);

        listView = (ListView) findViewById(R.id.listView_Total);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Toast.makeText(list_view_Activity.this, "这是" + i , Toast.LENGTH_SHORT).show();
            }
        });


        // 初始化信息

        // String name, String sex, String align, int HP, int Pw, int AC, int Xp
        for (int i = 0; i < 10; i++) {
            personList[i] = new Person("Sir, "+i+1, i % 2 == 1 ? "Female" : "Male", i % 2 == 0 ? "chaotic" : "Lawful", "p" + (i+1)+"",i+6, i+5, i+3, 0);
            // Toast.makeText(list_view_Activity.this, personList[i].getImg(), Toast.LENGTH_SHORT).show();
        }

        for (int i = 0; i < 10; i++) {
            myList.add(personList[i]);
        }

        MyPersonAdapter myPersonAdapter = new MyPersonAdapter(list_view_Activity.this, myList);
        myPersonAdapter.setOnInnerItemOnclickListener((MyPersonAdapter.InnerItemOnclickListener) list_view_Activity.this);
        listView.setAdapter(myPersonAdapter);
        listView.setOnItemClickListener((AdapterView.OnItemClickListener) list_view_Activity.this);
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        Toast.makeText(list_view_Activity.this, "整体Item", Toast.LENGTH_SHORT).show();
    }

    @Override
    public void itemClick(View view) {
        int postion;
        postion = (Integer) view.getTag();
        switch (view.getId()) {
            // TODO: more case.
            case R.id.Img_Icon:
                Toast.makeText(list_view_Activity.this, "这是" + myList.get(postion).getName() + "", Toast.LENGTH_SHORT).show();
                break;
            case R.id.AC:
                Toast.makeText(list_view_Activity.this, "这是" + myList.get(postion).getAC() + "", Toast.LENGTH_SHORT).show();
                break;
            case R.id.align:
                Toast.makeText(list_view_Activity.this, "这是" + myList.get(postion).getAlign() + "", Toast.LENGTH_SHORT).show();
                break;
            case R.id.HP:
                Toast.makeText(list_view_Activity.this, "这是" + myList.get(postion).getHP() + "", Toast.LENGTH_SHORT).show();
                break;
            default:
                Toast.makeText(list_view_Activity.this, "ButtonMe", Toast.LENGTH_SHORT).show();
                break;
        }
    }
}
